package com.lovesher.payment.service.service.impl;

import java.util.List;

import com.lovesher.payment.common.resposity.base.Page;
import com.lovesher.payment.common.resposity.base.Pageable;
import com.lovesher.payment.common.resposity.search.BaseSearch;
import com.lovesher.payment.common.service.BaseService;
import com.lovesher.payment.service.resposity.base.DaoBase;

/**
 * 
 * @author tupengxiong
 *
 * @param <T>
 * @param <D>
 */
@SuppressWarnings("rawtypes")
public abstract class BaseServiceImpl<T,D extends DaoBase> implements BaseService<T>{
	
	public abstract D getDao() ;

    @SuppressWarnings("unchecked")
    @Override
	public T selectById(Long id) {
    	return (T) getDao().selectById(id);
    }

    @Override
    public int deleteById(Long id){
    	return getDao().deleteById(id);
    }
    
    @SuppressWarnings("unchecked")
    @Override
	public T insert(T record){
    	return (T) getDao().insert(record);
    }
    
    @SuppressWarnings("unchecked")
    @Override
	public int update(T record){
    	return getDao().update(record);
    }
    
    @SuppressWarnings("unchecked")
    @Override
	public Page<T> findPage(Pageable pageable){
		return getDao().findPage(pageable);
    }
    
    @Override
	public Integer countPage(Pageable pageable){
		return getDao().countPage(pageable);
    } 
    
    @Override
    public void removeBeans(Long[] ids){
    	for(int i=0;i<ids.length;i++){
			Long tempId = ids[i];
			if(tempId != null){
				this.getDao().deleteById(tempId);
			}
		}
    }
    
    @SuppressWarnings("unchecked")
    @Override
	public List<T> findAll(){
		return getDao().findAll();
    }
    
    @SuppressWarnings("unchecked")
	public Page<T> findPageByBaseSearch(Pageable pageable,BaseSearch bean) {
		return getDao().findPageByBaseSearch(pageable, bean);
	}
    
    @Override
    public Integer count() {
    	return getDao().count();
    }
    
    @SuppressWarnings("unchecked")
    @Override
	public T selectByUserId(Long userId) {
    	return (T) getDao().selectByUserId(userId);
    }
}
